package com.xyh.ollama_test.controller;

import com.xyh.ollama_test.enums.Department;
import com.xyh.ollama_test.service.PermissionService;
import com.xyh.ollama_test.service.BgeM3Service;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/api/vector")
public class VectorController {
    private final BgeM3Service bgeM3Service;
    private final PermissionService permissionService;

    public VectorController(BgeM3Service bgeM3Service, PermissionService permissionService) {
        this.bgeM3Service = bgeM3Service;
        this.permissionService = permissionService;
    }

    @GetMapping("/store/{userId}/{text}")
    public Mono<String> vectorizeAndStore(@PathVariable String text, @PathVariable String userId) {
        Department userDept = permissionService.getUserDepartment(userId);
        if (!permissionService.hasPermission(userId,userDept)) {
            return Mono.just("无权限存储向量数据，请联系管理员");
        }
        return bgeM3Service.generateEmbeddingAndStore(text,userId);
    }
}